﻿<%@ WebHandler Language="C#" Class="SYS_Category_update" %>

using System;
using System.Web;
using System.Web.Script.Serialization;
using System.Collections.Generic;
using System.Web.SessionState;

public class SYS_Category_update : IHttpHandler,IRequiresSessionState {
    sqlhelp sql = new sqlhelp();
    result result = new result();
    string str = "";
    public void ProcessRequest (HttpContext context) {
        try
        {
            if (context.Session["comid"] == null)
            {
                result.code = "-1";
                result.msg = "用户未登录";
                unit.send(context, result);
                return;
            }
            
            string Id = "";
            string updateStr = "";
            if (context.Request["Id"] != null)
            {
                Id = context.Request["Id"].ToString();
            }
            else {
                result.code = "0";
                result.msg = "未传递商铺Id参数";
                unit.send(context, result);
                return;
            }
            
            string Code = ""; 
            if (context.Request["Code"] != null) { 
                Code = context.Request["Code"].ToString();
                updateStr = updateStr + " Code = " + Code + ",";
            } 
            string Name = ""; 
            if (context.Request["Name"] != null) { 
                Name = context.Request["Name"].ToString();
                updateStr = updateStr + " Name = '" + Name + "',";
            } 
            string CreateTime = ""; 
            if (context.Request["CreateTime"] != null) { 
                CreateTime = context.Request["CreateTime"].ToString();
                updateStr = updateStr + " CreateTime = '" + CreateTime + "',";
            } 
            string Enable = ""; 
            if (context.Request["Enable"] != null) { 
                Enable = context.Request["Enable"].ToString();
                updateStr = updateStr + " Enable = '" + Enable + "',";
            }

            if (updateStr == "")
            {
                result.code = "0";
                result.msg = "未传递修改参数";
                unit.send(context, result);
                return;
            }

            updateStr = updateStr.TrimEnd(',');

            str = "update SYS_Category set " + updateStr + " where Id = '" + Id + "'"; 
            if (sql.ExecuteNonQuery(str) > 0)
            {
                result.code = "1";
                result.msg = "";
            }
            else
            {
                result.code = "0";
                result.msg = "添加失败";
            }

        }
        catch (Exception e1)
        {
            result.code = "0";
            result.msg = e1.Message;
        }
        unit.send(context, result);
    }

    public bool IsReusable {
        get {
            return false;
        }
    }

}
